// vuex 2.0 创建vuex实例的写法是 new Vuex.store
// vuex 3.0 创建vuex实例的写法是 crateStore()
import { createStore } from 'vuex'

// A模块
const moduleA = {
  state: {
    username: 'moduleA'
  },
  getters: {
    newName (state) {
      return state.username + '!!!'
    }
  }
}

// B模块
const moduleB = {
  namespaced: true,
  state: {
    username: 'moduleB'
  },
  getters: {
    newName (state) {
      return state.username + '!!!'
    }
  },
  mutations: {
    updateName (state) {
      state.username = 'zs'
    }
  },
  actions: {
    updateName (state) {
      setTimeout(() => {
        state.commit('updateName')
      }, 2000)
    }
  }
}

export default createStore({
  modules: {
    moduleA,
    moduleB
  }
})
